package com.ymatou.iapi.trading.operate.testcase;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.json.JSONArray;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.OrderGroupVo;
import com.ymatou.iapi.trading.operate.parameter.OrderItemVo;
import com.ymatou.iapi.trading.operate.parameter.OrderVo;
import com.ymatou.iapi.trading.operate.parameter.SellerCouponVo;
import com.ymatou.iapi.trading.operate.parameter.YmatouCouponVo;
import com.ymatou.iapi.trading.operate.parameter.enums.AppTerminalSourceEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.OrderSourceEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.OrderTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.PriceTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.ProductRefundChannelEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.SalesTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.SellerCouponApplianceTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.TerminalSourceEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.YmatouCouponApplianceTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.req.BatchNoNeedPostPayBean;
import com.ymatou.iapi.trading.operate.parameter.req.PlaceOrderReq;
import com.ymatou.iapi.trading.operate.service.BatchNoNeedPostPayCall;
import com.ymatou.iapi.trading.operate.service.PlaceOrderCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.CouponCallService;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.database.model.YmtCouponPrivateUserBound;
import com.ymttest.database.mongo.YMatouSellerOrderWapper;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.database.sqlwapper.YmtCouponPrivateUserBoundWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
 * 无需补款 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_BatchNoNeedPostPay {
    private static BatchNoNeedPostPayBean bnnppbean;

    private static BatchNoNeedPostPayCall bnnppcall;

    @BeforeClass
    public static void setUp() {
        Logger.createResultFile("无需补款");
    }

    @Before
    public void caseUp() {

        bnnppbean = new BatchNoNeedPostPayBean();
        bnnppcall = new BatchNoNeedPostPayCall();
    }

    @AfterClass
    public static void tearDown() {
        Logger.generateResult(bnnppcall.getOpurl());
    }

    @After
    public void caseDown() {
        Logger.end();
    }

    // 创建一个买手多个订单 直播商品，使用平台优惠券，商家券
    private Map placeOrder2() {
        Map map = new HashMap();
        try {
            PlaceOrderReq placeorderBean = new PlaceOrderReq();
            PlaceOrderCall placeorderCall = new PlaceOrderCall();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));

            String productName = "auto自动化测试";
            String pic = "http://p243.img.ymatou.com:10243/upload/productdes/3afa103d4ec4466f824b9f0458d6f4e2.jpg";
            BigDecimal price = new BigDecimal(130);
            String productId = "auto123456";
            YmatouCouponVo ymtCoupon = new YmatouCouponVo();
            // 平台优惠券
            BigDecimal couponValue = new BigDecimal(13);
            String couponCode = new OrderCallService().receivePlatformCoupon(userId, couponValue);
            ymtCoupon.setApplianceType(YmatouCouponApplianceTypeEnum.ALL);
            ymtCoupon.setCouponCode(couponCode);
            ymtCoupon.setCouponValue(couponValue);
            placeorderBean.setAppId("AutoTest");
            placeorderBean.setYmatouCoupon(ymtCoupon);
            placeorderBean.setUserId(userId);
            placeorderBean.setRequestId(TestDataManager.getRandomUUID()
                    .toString());
            placeorderBean.setOrderSource(OrderSourceEnum.APP);
            placeorderBean.setAppTerminalSource(AppTerminalSourceEnum.Phone);
            placeorderBean.setTerminalSource(TerminalSourceEnum.IOS);
            placeorderBean.setAppTerminalSource(AppTerminalSourceEnum.Phone);
            OrderGroupVo groupVo1 = new OrderGroupVo();
            // 商家优惠券
            BigDecimal sellerCouponValue = new BigDecimal(15);
            String sellerCouponCode = new CouponCallService().receiveCouponInfo(sellerId, userId,
                    couponValue);
            SellerCouponVo sellerCoupon = new SellerCouponVo();
            sellerCoupon.setApplianceType(SellerCouponApplianceTypeEnum.ALL);
            sellerCoupon.setCouponCode(sellerCouponCode);
            sellerCoupon.setCouponValue(sellerCouponValue);
            groupVo1.setSellerCoupon(sellerCoupon);
            groupVo1.setSellerId(sellerId);
            List<OrderVo> orders = new ArrayList<OrderVo>();
            OrderVo ordervo1 = new OrderVo();
            ordervo1.setAutoCancelOrderHours(new BigDecimal(1));
            ordervo1.setOrderType(OrderTypeEnum.Spot);
            // 需要补款的订单
            ordervo1.setPaidFull(false);

            List<OrderItemVo> items = new ArrayList<OrderItemVo>();
            OrderItemVo orderitem1 = new OrderItemVo();

            orderitem1.setProductNum(1 + new Random().nextInt(5));
            orderitem1.setProductName(productName);
            orderitem1.setPriceType(PriceTypeEnum.VipPrice);
            orderitem1.setProductId(productId);
            orderitem1.setCatalogId(TestDataManager.getRandomUUID().toString());
            price = new BigDecimal(210);
            orderitem1.setEarnestPrice(price.subtract(new BigDecimal(170)));
            orderitem1.setProductPrice(price);
            orderitem1.setOriginalPrice(price);
            orderitem1.setSalesType(SalesTypeEnum.AlreadyInStock);
            orderitem1.setLogisticsType(LogisticsTypeEnum.SailProtect);
            orderitem1.setProductRefundChannel(ProductRefundChannelEnum.Official);
            orderitem1.setFirstCategoryId(111111111);
            orderitem1.setSecondCategoryId(22222222);
            orderitem1.setThirdCategoryId(3333333);
            items.add(orderitem1);
            ordervo1.setOrderItems(items);
            ordervo1.setFreight(new BigDecimal("55"));

            OrderItemVo orderitem2 = new OrderItemVo();

            orderitem2.setProductNum(1 + new Random().nextInt(5));
            orderitem2.setProductName(productName);
            orderitem2.setPriceType(PriceTypeEnum.VipPrice);
            orderitem2.setProductId(productId);
            orderitem2.setCatalogId(TestDataManager.getRandomUUID().toString());
            price = new BigDecimal(210);
            orderitem2.setEarnestPrice(price.subtract(new BigDecimal(163)));
            orderitem2.setProductPrice(price);
            orderitem2.setOriginalPrice(price);
            orderitem2.setSalesType(SalesTypeEnum.AlreadyInStock);
            orderitem2.setLogisticsType(LogisticsTypeEnum.SailProtect);
            orderitem2.setProductRefundChannel(ProductRefundChannelEnum.Official);
            orderitem2.setFirstCategoryId(111111111);
            orderitem2.setSecondCategoryId(22222222);
            orderitem2.setThirdCategoryId(3333333);
            OrderItemVo orderitem3 = new OrderItemVo();

            orderitem3.setProductNum(1 + new Random().nextInt(5));
            orderitem3.setProductName(productName);
            orderitem3.setPriceType(PriceTypeEnum.VipPrice);
            orderitem3.setProductId(productId);
            orderitem3.setCatalogId(TestDataManager.getRandomUUID().toString());
            price = new BigDecimal(210);
            orderitem3.setEarnestPrice(price.subtract(new BigDecimal(163)));
            orderitem3.setProductPrice(price);
            orderitem3.setOriginalPrice(price);
            orderitem3.setSalesType(SalesTypeEnum.AlreadyInStock);
            orderitem3.setLogisticsType(LogisticsTypeEnum.SailProtect);
            orderitem3.setProductRefundChannel(ProductRefundChannelEnum.Official);
            orderitem3.setFirstCategoryId(111111111);
            orderitem3.setSecondCategoryId(22222222);
            orderitem3.setThirdCategoryId(3333333);
            items.add(orderitem1);
            items.add(orderitem2);
            items.add(orderitem3);
            ordervo1.setOrderItems(items);
            ordervo1.setFreight(new BigDecimal("55"));

            // 第二个订单
            orders.add(ordervo1);
            orders.add(ordervo1);

            groupVo1.setOrders(orders);

            placeorderBean.setOrderGroups(Arrays.asList(groupVo1));
            placeorderCall.setData(placeorderBean);
            placeorderCall.callService();

            YmtCouponPrivateUserBoundWapper ymtCouponPrivate = new YmtCouponPrivateUserBoundWapper();
            List<YmtCouponPrivateUserBound> listCoupon = ymtCouponPrivate
                    .selectBysCouponCode(couponCode);
            int ymtBeforeCount = listCoupon.get(0).getiCouponUsedCount();
            List<YmtCouponPrivateUserBound> listCoupon2 = ymtCouponPrivate
                    .selectBysCouponCode(sellerCouponCode);
            int sellerBeforeCount = listCoupon2.get(0).getiCouponUsedCount();

            map.put("orderId", placeorderCall.getOrderIds());
            map.put("tradingId", placeorderCall.getTradingId());
        } catch (Exception e) {
            Logger.fail(e);
        }
        return map;
    }

    private void verifyDb(int orderId) {
        DefaultWapper database = new DefaultWapper();
        // 订单主表
        List<Map> ymtOrders = database.selectOrderByOderId(orderId);
        // 订单商品明细
        List<Map> ymtOrdersInfoList = database.selectOrderInfoByOderId(orderId);
        // 调整金额
        BigDecimal discount = (BigDecimal) ymtOrders.get(0).get("fDiscount");
        // 总付款金额
        BigDecimal totalPrice = (BigDecimal) ymtOrders.get(0).get("fTotalPrice");
        // 运费
        BigDecimal freight = (BigDecimal) ymtOrders.get(0).get("fFreight");
        // 定金金额
        BigDecimal orderPrice = (BigDecimal) ymtOrders.get(0).get("fOrderPrice");
        // 商家券
        BigDecimal sellerCouponAmount = (BigDecimal) ymtOrders.get(0).get("fSellerCouponAmount");
        // 平台券
        BigDecimal ymtCouponAmount = (BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount");

        // 申请调整的价格
        // BigDecimal orderDiscount = changeorderdiscountbean.getDiscount().divide(new
        // BigDecimal(1), 2, 4);
        // 申请调整的运费
        // BigDecimal orderFreight = changeorderdiscountbean.getFreight().divide(new BigDecimal(1),
        // 2, 4);

        Logger.verifyEquals(
                discount,
                orderPrice.subtract(totalPrice),
                "验证fDiscount");
        BigDecimal newPayableAmount =
                totalPrice.add(freight).add(discount).subtract(sellerCouponAmount).subtract(ymtCouponAmount);

        // 应付金额调整
        Logger.verifyEquals(
                newPayableAmount,
                (BigDecimal) ymtOrders.get(0).get("fPayableAmount"),
                "验证fPayableAmount");

        BigDecimal tempDicount = BigDecimal.ZERO;

        for (int i = 0; i < ymtOrdersInfoList.size(); i++) {
            // 订单商品信息表
            Map orderInfoMap = ymtOrdersInfoList.get(i);
            BigDecimal productPrice = (BigDecimal) orderInfoMap.get("fProductPrice");
            int proNum = (Integer) orderInfoMap.get("iAmount");

            BigDecimal rate = productPrice.multiply(new BigDecimal(proNum))
                    .divide(totalPrice, 2, BigDecimal.ROUND_HALF_UP);
            BigDecimal productDiscount = new BigDecimal(0);
            BigDecimal productFreight = new BigDecimal(0);


            if (i == ymtOrdersInfoList.size() - 1) {
                productDiscount = discount.subtract(tempDicount);
            }
            else {
                // 商品里的调整分摊金额
                productDiscount =
                        discount.multiply(productPrice.multiply(new BigDecimal(proNum))).
                                divide(totalPrice, 2, BigDecimal.ROUND_HALF_DOWN);
            }
            tempDicount = tempDicount.add(productDiscount);

            Logger.verifyEquals(
                    productDiscount,
                    (BigDecimal) orderInfoMap.get("fDiscount"),
                    "验证fDiscount");
        }



    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchNoNeedPostPay_001() {
        Logger.start(true, "批量无需补款成功");
        try {
            // 循环两次，增加两条补款记录
            Logger.comment("前置数据准备");
            ArrayList<Integer> list = new ArrayList<Integer>();
            int sellerId = 0;
            for (int i = 0; i < 2; i++) {
                // 创建订单
                Map map = new OrderCallService().appSaveOrder();
                int orderId = (Integer) map.get("orderId");
                sellerId = (Integer) map.get("sellerId");
                int userId = (Integer) map.get("userId");
                int tradingId = (Integer) map.get("tradingId");
                DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
                BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
                new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
                // 接单
                new OrderCallService().acceptOrder(orderId, sellerId);
                list.add(orderId);
            }
            Logger.comment("前置数据准备结束");
            bnnppbean.setOrderIds(list);
            bnnppbean.setSellerId(sellerId);
            // 发送请求
            bnnppcall.setData(bnnppbean);
            bnnppcall.callService();
            Logger.verifyEquals(ECode.SUCCESS, bnnppcall.getCode(), "验证Code");
            // 数据库验证
            DefaultWapper database = new DefaultWapper();
            for (int OrderId : list) {
                HashMap<String, Integer> m = new HashMap<String, Integer>();
                m.put("OrderId", OrderId);
                m.put("PaidInFull", 1);
                Logger.verifyEquals(1, database.selectOrder(m).size(), "验证订单表记录");
            }
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_BatchNoNeedPostPay_002() {
        Logger.start(false, "此订单不存在");
        try {
            // 循环两次，增加两条补款记录
            ArrayList<Integer> list = new ArrayList<Integer>();
            int sellerId = Integer.valueOf(EnvSetup.getData("BuyerId"));
            list.add(1254);
            bnnppbean.setOrderIds(list);
            bnnppbean.setSellerId(sellerId);
            // 发送请求
            bnnppcall.setData(bnnppbean);
            bnnppcall.callService();
            Logger.verifyEquals(ECode.SUCCESS, bnnppcall.getCode(), "验证Code");
            Logger.verifyEquals(true, bnnppcall.getReturnData().contains(ECode.FAILED201_MSG_11), "验证Msg包含:"
                    + ECode.FAILED201_MSG_11);
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_BatchNoNeedPostPay_003() {
        Logger.start(true, "订单状态不能操作无需补款");
        try {
            Logger.comment("前置数据准备");
            // 循环两次，增加两条补款记录
            ArrayList<Integer> list = new ArrayList<Integer>();
            int sellerId = 0;
            for (int i = 0; i < 2; i++) {
                // 创建订单
                Map map = new OrderCallService().appSaveOrder();
                int orderId = (Integer) map.get("orderId");
                sellerId = (Integer) map.get("sellerId");
                int userId = (Integer) map.get("userId");
                int tradingId = (Integer) map.get("tradingId");
                DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
                BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
                new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
                // 接单
                // new OrderCallService().acceptOrder(OrderId, SellerId);
                list.add(orderId);
            }
            Logger.comment("前置数据准备结束");
            bnnppbean.setOrderIds(list);
            bnnppbean.setSellerId(sellerId);
            // 发送请求
            bnnppcall.setData(bnnppbean);
            bnnppcall.callService();
            Logger.verifyEquals(ECode.SUCCESS, bnnppcall.getCode(), "验证Code");
            Logger.verifyEquals(true, bnnppcall.getReturnData().contains(ECode.FAILED201_MSG_48), "验证Msg包含信息:"
                    + ECode.FAILED201_MSG_48);
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchNoNeedPostPay_004() {
        Logger.start(true, "操作用户id为null");
        try {
            Logger.comment("前置数据准备");
            ArrayList<Integer> list = new ArrayList<Integer>();
            // 创建订单
            Map map = new OrderCallService().appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
            // 接单
            new OrderCallService().acceptOrder(orderId, sellerId);
            list.add(orderId);
            Logger.comment("前置数据准备结束");
            bnnppbean.setOrderIds(list);
            // bnnppbean.setSellerId(sellerId);
            // 发送请求
            bnnppcall.setData(bnnppbean);
            bnnppcall.callService();
            Logger.verifyEquals(ECode.ERROR400, bnnppcall.getCode(), "验证code");
            Logger.verifyEquals("sellerId:卖家操作id未提供", bnnppcall.getMsg(), "验证msg");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchNoNeedPostPay_005() {
        Logger.start(true, "订单列表为null,操作无需补款失败");
        try {
            bnnppbean.setOrderIds(null);
            bnnppbean.setSellerId(3383);
            // 发送请求
            bnnppcall.setData(bnnppbean);
            bnnppcall.callService();
            Logger.verifyEquals(ECode.ERROR400, bnnppcall.getCode(), "验证Code");
            Logger.verifyEquals("orderIds:订单列表不能为空", bnnppcall.getString("msg"),
                    "验证Msg包含信息");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchNoNeedPostPay_006() {
        Logger.start(true, "订单在退货退款中,操作无需补款失败");
        try {
            Logger.comment("前置数据准备");
            ArrayList<Integer> list = new ArrayList<Integer>();
            // 创建订单
            OrderCallService orderService = new OrderCallService();
            Map map = new OrderCallService().appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            // 买家付款
            orderService.orderPayRequest(userId, totalPrice, tradingId);
            // 退货退款同步
            orderService.applySalesRefundRequestInJava(orderId);
            list.add(orderId);
            Logger.comment("前置数据准备结束");
            bnnppbean.setOrderIds(list);
            bnnppbean.setSellerId(sellerId);
            // 发送请求
            bnnppcall.setData(bnnppbean);
            bnnppcall.callService();
            Logger.verifyEquals(ECode.SUCCESS, bnnppcall.getCode(), "验证Code");
            Logger.verifyEquals(true, bnnppcall.getReturnData().contains(ECode.FAILED201_MSG_62), "验证Msg包含信息:"
                    + ECode.FAILED201_MSG_62);
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchNoNeedPostPay_007() {
        Logger.start(true, "一笔交易多个订单,付定金后，操作无需补款，校验商品调整金额分摊");
        try {
            Logger.comment("前置数据准备");
            ArrayList<Integer> list = new ArrayList<Integer>();
            // 创建订单
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            OrderCallService orderService = new OrderCallService();
            Map map = placeOrder2();
            JSONArray orderIds = (JSONArray) map.get("orderId");
            int tradingId = (Integer) map.get("tradingId");
            BigDecimal totalAmount = BigDecimal.ZERO;
            // 创建订单
            for (int i = 0; i < orderIds.length(); i++) {
                int orderId = orderIds.getInt(i);
                totalAmount = orderService.getNeedPrePayAmountOfCash(orderId).add(totalAmount);
                list.add(orderId);
            }
            // 买家付款
            orderService.orderPayRequest(userId, totalAmount, tradingId);
            // 批量接单
            orderService.batchAcceptOrders(sellerId, list);
            Logger.comment("前置数据准备结束");
            bnnppbean.setOrderIds(list);
            bnnppbean.setSellerId(sellerId);
            // 发送请求
            bnnppcall.setData(bnnppbean);
            bnnppcall.callService();
            Logger.verifyEquals(ECode.SUCCESS, bnnppcall.getCode(), "验证Code");
            for (int orderId : list) {
                Logger.comment("检验订单号:" + orderId + "无需补款后的，商品调整金额分摊");
                verifyDb(orderId);
            }
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchNoNeedPostPay_008() {
        Logger.start(true, "一笔交易多个订单,付定金后，操作无需补款，买手可以正常发货");
        try {
            Logger.comment("前置数据准备");
            ArrayList<Integer> list = new ArrayList<Integer>();
            // 创建订单
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            OrderCallService orderService = new OrderCallService();
            Map map = placeOrder2();
            JSONArray orderIds = (JSONArray) map.get("orderId");
            int tradingId = (Integer) map.get("tradingId");
            BigDecimal totalAmount = BigDecimal.ZERO;
            // 创建订单
            for (int i = 0; i < orderIds.length(); i++) {
                int orderId = orderIds.getInt(i);
                totalAmount = orderService.getNeedPrePayAmountOfCash(orderId).add(totalAmount);
                list.add(orderId);
            }
            // 买家付款
            orderService.orderPayRequest(userId, totalAmount, tradingId);
            // 批量接单
            orderService.batchAcceptOrders(sellerId, list);
            Logger.comment("前置数据准备结束");
            bnnppbean.setOrderIds(list);
            bnnppbean.setSellerId(sellerId);
            // 发送请求
            bnnppcall.setData(bnnppbean);
            bnnppcall.callService();
            Logger.verifyEquals(ECode.SUCCESS, bnnppcall.getCode(), "验证Code");
            for (int orderId : list) {
                // 发货
                orderService.dispatched(orderId, sellerId);
                // 订单主表
                List<Map> ymtOrders = new DefaultWapper().selectOrderByOderId(orderId);
                Logger.verifyEquals(3, (Integer) ymtOrders.get(0).get("iTradingStatus"), "验证订单" + orderId + "状态为3，已发货");
            }
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchNoNeedPostPay_009() {
        Logger.start(true, "批量无需补款成功,校验同步到Mongo数据库");
        try {
            // 循环两次，增加两条补款记录
            Logger.comment("前置数据准备");
            ArrayList<Integer> list = new ArrayList<Integer>();
            int sellerId = 0;
            for (int i = 0; i < 2; i++) {
                // 创建订单
                Map map = new OrderCallService().appSaveOrder();
                int orderId = (Integer) map.get("orderId");
                sellerId = (Integer) map.get("sellerId");
                int userId = (Integer) map.get("userId");
                int tradingId = (Integer) map.get("tradingId");
                DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
                BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
                new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
                // 接单
                new OrderCallService().acceptOrder(orderId, sellerId);
                list.add(orderId);
            }
            Logger.comment("前置数据准备结束");
            bnnppbean.setOrderIds(list);
            bnnppbean.setSellerId(sellerId);
            // 发送请求
            bnnppcall.setData(bnnppbean);
            bnnppcall.callService();
            Logger.verifyEquals(ECode.SUCCESS, bnnppcall.getCode(), "验证Code");
            // 数据库验证
            // 检查点
            YMatouSellerOrderWapper sellerorderwapper = new YMatouSellerOrderWapper();
            Map result = null;
            int count = 0;
            int orderId1 = bnnppbean.getOrderIds().get(0);
            // 重试3次
            while (result == null && count < 30) {
                Thread.sleep(1000);
                result = sellerorderwapper.selectOrderInfoById(orderId1, sellerId);
                count++;
            }
            Logger.comment("Mongo中查询出的订单信息:" + result.toString());
            Logger.verifyEquals(orderId1, (Integer) result.get("_id"), "验证OrderId");
            Logger.verifyEquals(sellerId, (Integer) result.get("Seller"), "验证Seller");
            Logger.verifyEquals(17, (Integer) result.get("TradingStatus"), "验证TradingStatus");
            Logger.verifyEquals(1, (Integer) result.get("Type"), "验证Type");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }
}
